﻿#pragma once
#include "AsEnvironmentBasics.h"

__AS_JY(Update 2023.1.8)
class ADF_EXPORT AsEnvironmentVariables {
public:
	AsEnvironmentVariables();
	enum SaveMode {
		ManualSave,
		AutoSave
	};
	
private:
	AsJsonFile	mJsonFile;
	QTimer		mSaveTimer;
	bool		mFlagSave;
	QString		mFilename;

private:
	void executeVaraiblesSave();

public:
	void setupEnvironmentVariables(SaveMode saveMode = SaveMode::AutoSave);
	void setupEnvironmentVariables(const QString& filename, SaveMode saveMode = SaveMode::AutoSave);
	void setupEnvironmentVariables(const QString& filename, const AsEnvVariablesTable& table, SaveMode saveMode = SaveMode::AutoSave);
	void setupEnvironmentVariables(const AsEnvVariablesTable& table, SaveMode saveMode = SaveMode::AutoSave);
	void setEnvironmentVariablesFilename(const QString& filename);
	void setEnvironmentVariablesAutoSave(bool isEnable);
	void saveEnvironmentVariables();

public:
	bool containsEnvironmentVariable(const QString& name);
	void defEnvironmentVariable(const QString& name, const AsEnvVariable& variable);
	AsEnvVariable getEnvironmentVariable(const QString& name) const;
	void setEnvironmentVariable(const QString& name, const AsEnvVariable& variable);
	void clearEnvironmentVariables();

	inline bool			containsVar(const QString& name)						 { return containsEnvironmentVariable(name); }
	inline void			defVar(const QString& name, const AsEnvVariable& variable) { defEnvironmentVariable(name, variable); }
	inline AsEnvVariable	getVar(const QString& name) const						 { return getEnvironmentVariable(name);  }
	inline void			setVar(const QString& name, const AsEnvVariable& variable) { setEnvironmentVariable(name, variable); }
	inline void			clearVars()												 { clearEnvironmentVariables(); }

	inline bool		getBool(const QString& name)	const { return getEnvironmentVariable(name).toBool(); }
	inline int		getInt(const QString& name)		const { return getEnvironmentVariable(name).toInt(); }
	inline qint64	getInt64(const QString& name)	const { return getEnvironmentVariable(name).toVariant().toLongLong(); }
	inline double	getDouble(const QString& name)	const { return getEnvironmentVariable(name).toDouble(); }
	inline QString	getString(const QString& name)	const { return getEnvironmentVariable(name).toString(); }

};

